package org.mine.design.decorator.controller;

import org.mine.design.decorator.data.RiderOrder;
import org.mine.design.decorator.service.impl.MerchantOrderDeliveryAbstractServiceImpl;
import org.mine.design.decorator.service.impl.PartOrderDeliveryAbstractServiceImpl;
import org.mine.design.decorator.service.impl.SignedOrderDeliveryAbstractServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DecoratorController {

    @Autowired
    private MerchantOrderDeliveryAbstractServiceImpl merchantOrderDeliveryAbstractService;

    @Autowired
    private PartOrderDeliveryAbstractServiceImpl partOrderDeliveryAbstractService;

    @Autowired
    private SignedOrderDeliveryAbstractServiceImpl signedOrderDeliveryAbstractService;


    /**
     * 模拟不同外卖员配送订单流程 (平台签约外卖员、兼职/众包外卖员、商家配送)
     * 说明：流程分为三个阶段 接单 -> 配送 -> 完成
     * <p>
     * 相同点：各阶段需要记录日志，且修改订单状态
     * 不同点：
     * 1.平台签约外卖员在各阶段流程中，需要向平台报备信息
     * 2.平台签约外卖员、商家配送为指定订单，兼职/众包外卖员需要抢单，所以兼职/众包外卖员在接单阶段需要判断当前订单是否属于当前骑手
     * 3.平台签约外卖员、兼职/众包外卖员配送完成需要结算收益，商家配送无须结算
     */
    @RequestMapping("/decorator/test")
    public void test() {

        this.merchantFlow();

        this.signedFlow();

        this.partFlow();

    }

    private void merchantFlow() {
        RiderOrder riderOrder = new RiderOrder();
        merchantOrderDeliveryAbstractService.accept(riderOrder);
        merchantOrderDeliveryAbstractService.delivery(riderOrder);
        merchantOrderDeliveryAbstractService.complete(riderOrder);
    }

    private void partFlow() {
        RiderOrder riderOrder = new RiderOrder();
        partOrderDeliveryAbstractService.accept(riderOrder);
        partOrderDeliveryAbstractService.delivery(riderOrder);
        partOrderDeliveryAbstractService.complete(riderOrder);
    }

    private void signedFlow() {
        RiderOrder riderOrder = new RiderOrder();
        signedOrderDeliveryAbstractService.accept(riderOrder);
        signedOrderDeliveryAbstractService.delivery(riderOrder);
        signedOrderDeliveryAbstractService.complete(riderOrder);
    }
}
